let searchInputs = document.getElementById("search-input");
let searchDiv = document.getElementById("search-div");
let searchUl = searchDiv.getElementsByTagName("ul")[0];
let searchLi = searchUl.getElementsByTagName("li");
let arr = ['小米','小米 mix foid','小米11 pro','小米 Uttra','小米 10S','小米 11','小米 室外摄像机电池板','小米 10','小米手表','小米 11青春版'];
let air = ['全部商品','小米11','小米10s','小米手机','洗衣机','空调'];
var str = "";
searchInputs.onfocus = function(){
    if(searchInputs != "" && !str) {
        searchUl.innerHTML = '<li><a href="#">您搜索的内容不存在</a></li>';;
    }
    searchDiv.style.display = "block";
    if(searchInputs.value == "") {
        str = "";
        air.forEach((items) =>{
            str += '<li><a href="#">' + items +'</a></li>';
            searchUl.innerHTML = str;
        })
    }
    searchInputs.oninput = function(){
        str = "";
        if (searchInputs.value != "") {
            str = "";
            arr.forEach((item) => {
                let res = item.indexOf(searchInputs.value);
                if (res != -1) {
                    str += '<li><a href="#">' + item +'</a></li>';
                    searchUl.innerHTML = str;
                }
            });
        }
        if(searchInputs.value == ""){
            str = "";
            air.forEach((items) =>{
                str += '<li><a href="#">' + items +'</a></li>';
                searchUl.innerHTML = str;
            })
        }
        if(!str || !searchInputs) {
            searchUl.innerHTML = '<li><a href="#">您搜索的内容不存在</a></li>';;
        }
    }
}
searchUl.onmousedown = function (event) {
    event.preventDefault();
}
searchInputs.onblur = function(){
    searchDiv.style.display = "none";
}